CREATE TABLE [dbo].[AddressMain]
(
[AddressKey] [uniqueidentifier] NOT NULL,
[IsPhysicalAddress] [bit] NOT NULL,
[AddressStatusCode] [nchar] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[FormattedAddress] [nvarchar] (300) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[LastVerifiedOn] [datetime] NULL,
[BadAddressReasonKey] [uniqueidentifier] NULL,
[UpdatedOn] [datetime] NOT NULL,
[UpdatedByUserKey] [uniqueidentifier] NOT NULL,
[CreatedByUserKey] [uniqueidentifier] NOT NULL,
[CreatedOn] [datetime] NOT NULL,
[SystemEntityKey] [uniqueidentifier] NOT NULL,
[AddressCategoryCode] [int] NOT NULL CONSTRAINT [DF_AddressMain_AddressCategoryCode] DEFAULT ((0)),
[OwnerContactKey] [uniqueidentifier] NULL,
[MarkedForDeleteOn] [datetime] NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[AddressMain] ADD CONSTRAINT [PK_AddressMain] PRIMARY KEY CLUSTERED ([AddressKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_AddressMain_FormattedAddress] ON [dbo].[AddressMain] ([FormattedAddress]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[AddressMain] ADD CONSTRAINT [FK_AddressMain_AddressCategoryRef] FOREIGN KEY ([AddressCategoryCode]) REFERENCES [dbo].[AddressCategoryRef] ([AddressCategoryCode])
GO
ALTER TABLE [dbo].[AddressMain] ADD CONSTRAINT [FK_AddressMain_AddressStatusRef] FOREIGN KEY ([AddressStatusCode]) REFERENCES [dbo].[AddressStatusRef] ([AddressStatusCode])
GO
ALTER TABLE [dbo].[AddressMain] ADD CONSTRAINT [FK_AddressMain_BadAddressRef] FOREIGN KEY ([BadAddressReasonKey]) REFERENCES [dbo].[BadAddressReasonRef] ([BadAddressReasonKey])
GO
ALTER TABLE [dbo].[AddressMain] ADD CONSTRAINT [FK_AddressMain_ContactMain] FOREIGN KEY ([OwnerContactKey]) REFERENCES [dbo].[ContactMain] ([ContactKey])
GO
ALTER TABLE [dbo].[AddressMain] ADD CONSTRAINT [FK_AddressMain_SystemEntity] FOREIGN KEY ([SystemEntityKey]) REFERENCES [dbo].[SystemEntity] ([SystemEntityKey])
GO
ALTER TABLE [dbo].[AddressMain] ADD CONSTRAINT [FK_AddressMain_UserMain_CreatedBy] FOREIGN KEY ([CreatedByUserKey]) REFERENCES [dbo].[UserMain] ([UserKey])
GO
ALTER TABLE [dbo].[AddressMain] ADD CONSTRAINT [FK_AddressMain_UserMain_UpdatedBy] FOREIGN KEY ([UpdatedByUserKey]) REFERENCES [dbo].[UserMain] ([UserKey])
GO